<?php
if (is_array($arrTTopicsall)) {
    $i = 0;
    foreach ($arrTTopicsall as $key) {
        $arrTTopics1[] = $arrTTopicsall[$i];
        $i = $i + 4;
    }
    $arrTTopics1 = array_filter($arrTTopics1);
    if (is_array($arrTTopics1)) {
        foreach ($arrTTopics1 as $key => $item) {
            $arrTTopic1[] = $item;
            $arrTTopic1[$key]['user'] = aac('user', $db)->getSimpleUser($item['userid']);
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_index where topicid=" . $item['topicid'] . "");
            $last_return = $db->once_fetch_assoc("select * from " . dbprefix .
                "group_topics_comments where topicid=" . $item['topicid'] .
                " order by addtime desc limit 1");
            $arrTTopic1[$key]['last_return'] = $last_return['content'];
            $arrTTopic1[$key]['lastreturnuser'] = aac('user', $db)->getSimpleUser($last_return['userid']);
            $arrTTopic1[$key]['tags'] = aac('tag')->getObjTagByObjid('topic', 'topicid', $item['topicid']);
            $arrTTopic1[$key]['collects_num'] = $db->once_num_rows("select * from " .
                dbprefix . "group_topics_collects where topicid=" . $item['topicid'] . "");
            $arrTTopic1[$key]['iscollect'] = $db->once_num_rows("select * from " . dbprefix .
                "group_topics_collects where userid=" . $userid . " and topicid = " . $item['topicid'] .
                "");
            if ($thumbimg) {
                $arrTTopic1[$key]['thumb'] = $thumbimg['indeximgurl'];
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "w200.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "200", "", "0", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_index (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
                $arrTTopic1[$key]['thumb'] = $imgurl;
            }
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_topic where topicid=" . $item['topicid'] . "");
            if ($thumbimg && strstr($thumbimg['indeximgurl'], 't100x100')) {
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "t100x100.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "100", "100", "1", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_topic (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
            }
        }
    }
}

if (is_array($arrTTopicsall)) {
    $i = 1;
    foreach ($arrTTopicsall as $key) {
        $arrTTopics2[] = $arrTTopicsall[$i];
        $i = $i + 4;
    }
    $arrTTopics2 = array_filter($arrTTopics2);
    if (is_array($arrTTopics2)) {
        foreach ($arrTTopics2 as $key => $item) {
            $arrTTopic2[] = $item;
            $arrTTopic2[$key]['user'] = aac('user', $db)->getSimpleUser($item['userid']);
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_index where topicid=" . $item['topicid'] . "");
            $last_return = $db->once_fetch_assoc("select * from " . dbprefix .
                "group_topics_comments where topicid=" . $item['topicid'] .
                " order by addtime desc limit 1");
            $arrTTopic2[$key]['last_return'] = $last_return['content'];
            $arrTTopic2[$key]['lastreturnuser'] = aac('user', $db)->getSimpleUser($last_return['userid']);
            $arrTTopic2[$key]['tags'] = aac('tag')->getObjTagByObjid('topic', 'topicid', $item['topicid']);
            $arrTTopic2[$key]['collects_num'] = $db->once_num_rows("select * from " .
                dbprefix . "group_topics_collects where topicid=" . $item['topicid'] . "");
            $arrTTopic2[$key]['iscollect'] = $db->once_num_rows("select * from " . dbprefix .
                "group_topics_collects where userid=" . $userid . " and topicid = " . $item['topicid'] .
                "");
            if ($thumbimg) {
                $arrTTopic2[$key]['thumb'] = $thumbimg['indeximgurl'];
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "w200.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "200", "", "0", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_index (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
                $arrTTopic2[$key]['thumb'] = $imgurl;
            }
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_topic where topicid=" . $item['topicid'] . "");
            if ($thumbimg && strstr($thumbimg['indeximgurl'], 't100x100')) {
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "t100x100.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "100", "100", "1", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_topic (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
            }
        }
    }
}

if (is_array($arrTTopicsall)) {
    $i = 2;
    foreach ($arrTTopicsall as $key) {
        $arrTTopics3[] = $arrTTopicsall[$i];
        $i = $i + 4;
    }
    $arrTTopics3 = array_filter($arrTTopics3);
    if (is_array($arrTTopics3)) {
        foreach ($arrTTopics3 as $key => $item) {
            $arrTTopic3[] = $item;
            $arrTTopic3[$key]['user'] = aac('user', $db)->getSimpleUser($item['userid']);
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_index where topicid=" . $item['topicid'] . "");
            $last_return = $db->once_fetch_assoc("select * from " . dbprefix .
                "group_topics_comments where topicid=" . $item['topicid'] .
                " order by addtime desc limit 1");
            $arrTTopic3[$key]['last_return'] = $last_return['content'];
            $arrTTopic3[$key]['lastreturnuser'] = aac('user', $db)->getSimpleUser($last_return['userid']);
            $arrTTopic3[$key]['tags'] = aac('tag')->getObjTagByObjid('topic', 'topicid', $item['topicid']);
            $arrTTopic3[$key]['collects_num'] = $db->once_num_rows("select * from " .
                dbprefix . "group_topics_collects where topicid=" . $item['topicid'] . "");
            $arrTTopic3[$key]['iscollect'] = $db->once_num_rows("select * from " . dbprefix .
                "group_topics_collects where userid=" . $userid . " and topicid = " . $item['topicid'] .
                "");
            if ($thumbimg) {
                $arrTTopic3[$key]['thumb'] = $thumbimg['indeximgurl'];
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "w200.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "200", "", "0", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_index (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
                $arrTTopic3[$key]['thumb'] = $imgurl;
            }
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_topic where topicid=" . $item['topicid'] . "");
            if ($thumbimg && strstr($thumbimg['indeximgurl'], 't100x100')) {
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "t100x100.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "100", "100", "1", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_topic (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
            }
        }
    }
}

if (is_array($arrTTopicsall)) {
    $i = 3;
    foreach ($arrTTopicsall as $key) {
        $arrTTopics4[] = $arrTTopicsall[$i];
        $i = $i + 4;
    }
    $arrTTopics4 = array_filter($arrTTopics4);
    if (is_array($arrTTopics4)) {
        foreach ($arrTTopics4 as $key => $item) {
            $arrTTopic4[] = $item;
            $arrTTopic4[$key]['user'] = aac('user', $db)->getSimpleUser($item['userid']);
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_index where topicid=" . $item['topicid'] . "");
            $last_return = $db->once_fetch_assoc("select * from " . dbprefix .
                "group_topics_comments where topicid=" . $item['topicid'] .
                " order by addtime desc limit 1");
            $arrTTopic4[$key]['last_return'] = $last_return['content'];
            $arrTTopic4[$key]['lastreturnuser'] = aac('user', $db)->getSimpleUser($last_return['userid']);
            $arrTTopic4[$key]['tags'] = aac('tag')->getObjTagByObjid('topic', 'topicid', $item['topicid']);
            $arrTTopic4[$key]['collects_num'] = $db->once_num_rows("select * from " .
                dbprefix . "group_topics_collects where topicid=" . $item['topicid'] . "");
            $arrTTopic4[$key]['iscollect'] = $db->once_num_rows("select * from " . dbprefix .
                "group_topics_collects where userid=" . $userid . " and topicid = " . $item['topicid'] .
                "");
            if ($thumbimg) {
                $arrTTopic4[$key]['thumb'] = $thumbimg['indeximgurl'];
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "w200.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "200", "", "0", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_index (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
                $arrTTopic4[$key]['thumb'] = $imgurl;
            }
            $thumbimg = $db->once_fetch_assoc("select * from " . dbprefix .
                "thumb_topic_topic where topicid=" . $item['topicid'] . "");
            if ($thumbimg && strstr($thumbimg['indeximgurl'], 't100x100')) {
            } else {
                $random = random(14);
                $imgurl = "cache/thumb/index/" . $random . "t100x100.jpg";
                $oldimgurl = $new['home']->getfristimg($item['content']);
                $arr_img = getimagesize($oldimgurl);
                $resizeimage = new resizeimage("$oldimgurl", "100", "100", "1", "$imgurl");
                $tid = $item['topicid'];
                $db->query("INSERT INTO " . dbprefix .
                    "thumb_topic_topic (`topicid`,`indeximgurl`) VALUES ('$tid','$imgurl')");
            }
        }
    }
}
